<?
/*
-------------------------------
Script - EvaGb
-------------------------------
File - admin.php
-------------------------------
Function - Админцентр
-------------------------------
*/

session_start();
##################################
# Init
##################################
include_once "engine/config.php";
include_once "{$GLOBALS['_gb_cnf']['dir']}/sis/inc/support_inc.php";
include_once "{$GLOBALS['_gb_cnf']['dir']}/sis/inc/gzip_inc.php";

function __autoload($class_name) {
     include_once("{$GLOBALS['_gb_cnf']['dir']}/sis/classes/".$class_name . ".class.php");
}
##################################
$result=array();
$db=locator::get()->db();
$tpl=locator::get()->tpl();
locator::get()->save['admin']=new admin();
$tpl->set_global('cnf',$GLOBALS['_gb_cnf']);
$do=$_GET['do'];

##################################
#   Do_Names
##################################

$dos=array(
       "editmsg"=>"Редактор Сообщений",
       "editonepost"=>"Редактирование Сообщения",
       "delpost"=>"Удаление Сообщения",
       "banpost"=>"Добавление IP в чёрный список",
       "rebanpost"=>"Удаление IP из чёрного списка",
       
       "out"=>"Выход",
    );

##################################
$adm=locator::get()->save['admin'];
if (rights::is_admin()) {
   $tpl->set_global('user',$_SESSION['_db_user']);
   if ($dos[$do]) {
       $result['do_name']=$dos[$do];
       include "{$GLOBALS['_gb_cnf']['dir']}/sis/classes/adm/".$do.".php";
       $mod=new admin_modul();
       $result['content']=$mod->result;
       $result['error']=$mod->error;
   }else {
     $result['do_name']="Статистика";
     if(!$tpl->is_cached("admin_tpl/statistic.tpl")) {
       $tpl->set(
        array(
           "allpost"=>@$db->result($db->query("SELECT COUNT(*) FROM {$db->pref}_post")),
           "allban"=>@$db->result($db->query("SELECT COUNT(*) FROM {$db->pref}_badip")),
           "todaypost"=>@$db->result($db->query("SELECT COUNT(*) FROM {$db->pref}_post WHERE data<='".time()."' AND data>='".(time()-3600*24)."'")),
           "zachas"=>@$db->result($db->query("SELECT COUNT(*) FROM {$db->pref}_post WHERE data<=".time()." AND data>=".(time()-3600))),
           "namepastpost"=>@$db->result($db->query("SELECT `name` FROM {$db->pref}_post ORDER BY data DESC")),
           "datapastpost"=>date("d.m.Y H:i",@$db->result($db->query("SELECT `data` FROM {$db->pref}_post ORDER BY data DESC"))),
            )
       );
        $result['content']=$tpl->load("admin_tpl/statistic.tpl",true);
     }else {
        $result['content']=$tpl->get_cache("admin_tpl/statistic.tpl");
     }
   }
}else {
   $s=true;
   $result['do_name']="Авторизация";
   if (issetpost("login,pass")) {
       if (!emptypost("login,pass")) {
           if ($adm->auth($_POST['login'],$_POST['pass'])) {
               $s=false;
               header("Refresh:2");
               $_SESSION['_gb_user']['rights']['admin']=1;
               $_SESSION['_gb_user']['name']=$_POST['login'];
               $result['error']="Вход...";
           } else {
               $result['error']=$adm->error;
           }
       }else {
           $result['error']="Ошибка: Обязательные поля нужно заполнить";
       }
   }
   if($s){
     $result['content']=$tpl->load('admin_tpl/auth.tpl');
   }
}

 $tpl->set('result',$result);
 $tpl->set('sw',$_GET['sw']);
 $_SESSION['page_refer']=$_SERVER['REQUEST_URI'];
 print gzip($tpl->load('admin_tpl/main.tpl'));
?>
